<template>
  <a-modal :maskClosable="false" v-model="visible" title="新增分期产品" width="1200px" @ok="submit">
    <entity-view :operator-type="operationType" :model="beanInfo" @submit="submit" :rules="rules" ref="form">
      <form-item label="分期产品代码" v-model="beanInfo.prodStageCode" prop="prodStageCode" :max-length="32"></form-item>
      <form-item label="分期产品名称" v-model="beanInfo.prodStageName" prop="prodStageName" :max-length="64"></form-item>
      <form-item label="分期期数" v-model="beanInfo.prodStageNum" prop="prodStageNum" :max-length="2"></form-item>
      <form-item label="分期手续费收取方式" v-model="beanInfo.prodStageFeeType" prop="prodStageFeeType" input-type="radioGroup" :options="[
        {label: '一次性收取', value: '0'},
        {label: '分期收取', value: '1'},
      ]"></form-item>
      <form-item label="分期费率(‰)" v-model="beanInfo.prodStageFee" prop="prodStageFee" :max-length="3"></form-item>
      <form-item label="分期产品描述" v-model="beanInfo.prodStageDesc" prop="prodStageDesc" :max-length="256"></form-item>
    </entity-view>
  </a-modal>
</template>

<script>
import {operationType as OT} from '../../../../utils/enum'
import EntityView from '../../../../components/common/entityView/EntityView.vue'
import FormItem from '../../../../components/common/entityView/FormItem.vue'

export default {
  name: 'installmentProducts',
  components: {EntityView, FormItem},
  data: function () {
    return {
      operationType: OT.ADD,
      visible: false,
      beanInfo: {},
      index: 0,
      rules: {
        prodStageCode: [{required: true, message: '请输入分期产品代码', trigger: 'blur'}],
        prodStageName: [{required: true, message: '请输入分期产品名称', trigger: 'blur'}],
        prodStageNum: [{required: true, message: '请输入分期期数', trigger: 'blur'}],
        prodStageFeeType: [{required: true, message: '请选择分期手续费收取方式', trigger: 'blur'}],
        prodStageFee: [{required: true, message: '请输入分期费率(‰)', trigger: 'blur'}],
        // prodStageDesc: [{required: true, message: '请输入分期产品描述', trigger: 'blur'}],
      }
    }
  },
  methods: {
    setBeanInfo (type,{...beanInfo},index) {
      this.beanInfo = beanInfo;
      this.operationType = type;
      this.index = index;
    },

    async submit () {
      try {
          const confirm = await this.$refs.form.validate();
          if (confirm) {
            this.visible = false
            this.$emit('submit')
          }
      } catch (e) {
          console.error(e)
      }
    }
  }
}
</script>

<style scoped>

</style>
